﻿var SPListCreationMenu = {
    addEvent: function (eventName, func) {
        if (window.attachEvent) {
            window.attachEvent("on" + eventName, func);
        } else if (window.addEventListener) {
            window.addEventListener(eventName, func, false);
        }
    }
};

SPListCreationMenu.addEvent("load", function () {
    if (location.pathname.toLowerCase().indexOf("/_layouts/create.aspx") >= 0 && GetUrlKeyValue("SPListCreationMenu", true)) {
        removeAllStatus(true);
        var tables = document.getElementsByTagName("table");
        for (var i = 0; i < tables.length; i++) {
            var table = tables[i];
            if (table.className != "ms-create-lists-table") continue;
            var row = table.getElementsByTagName("tr")[0];
            var cells = row.childNodes;
            for (var j = 0; j < cells.length; j++) {
                var cell = cells[j];
                if (j == cells.length - 1) {
                    // last
                    cell.style.width = "0";
                    cell.style.display = "none";
                } else {
                    cell.style.width = "25%";
                }
            }
            break;
        }
    }

    var curLang = _spPageContextInfo.currentLanguage;
    if (SPListCreationMenu.DefaultLanguage != curLang && SPListCreationMenu.Resources[curLang]) {
        var res = SPListCreationMenu.Resources[curLang];
        var menuItems = document.getElementsByTagName("ie:menuitem");
        for (var i = 0; i < menuItems.length; i++) {
            var menuItem = menuItems[i];
            var iconSrc = menuItem.getAttribute("iconSrc");
            if (!iconSrc || iconSrc.indexOf("/Lists/SPListCreationMenuFiles/") < 0) continue;
            var text = menuItem.getAttribute("text");
            if (text == "New Custom List") {
                menuItem.setAttribute("text", res.NewCustomListTitle);
                menuItem.setAttribute("description", res.NewCustomListDescription);
            } else if (text == "New List or Library") {
                menuItem.setAttribute("text", res.NewListOrLibraryTitle);
                menuItem.setAttribute("description", res.NewListOrLibraryDescription);
                break;
            }
        }
    }
});
